using System;
using System.Collections.Generic;
using System.Text;

//Copyright 2007 Iain Bapty
//
//This file is part of the ITunes Tag Manager.
//
//ITunes Tag Manager is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//ITunes Tag Manager is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with ITunes Tag Manager.  If not, see <http://www.gnu.org/licenses/>.

namespace ITunesManager
{
    class StringHelper
    {
        public static string fixStringCapatalisation(string originalSentence)
        {
            StringBuilder fixedSentence = new StringBuilder(originalSentence);

            Boolean newWord = true;
            for (int i = 0; i <= fixedSentence.Length - 1; i++)
            {
                if (newWord && !char.IsSymbol(fixedSentence[i]) && !char.IsPunctuation(fixedSentence[i]))
                {
                    fixedSentence[i] = char.ToUpper(fixedSentence[i]);
                    newWord = false;
                }
                else if (char.IsWhiteSpace(fixedSentence[i]))
                {
                    newWord = true;
                }
                else if (char.IsSymbol(fixedSentence[i]) || char.IsPunctuation(fixedSentence[i]))
                {
                    newWord = false;
                    continue;
                }
                else
                {
                    fixedSentence[i] = char.ToLower(fixedSentence[i]);
                }
            }

            return fixedSentence.ToString();        
        }
    }
}
